package com.ruoyi.eqmonitor.smdtv.controller;

import java.util.List;

import com.ruoyi.eqmonitor.smdtv.domain.SmdtvRainwater;
import com.ruoyi.eqmonitor.smdtv.service.ISmdtvRainwaterService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import java.util.Arrays;
import java.util.Date;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.security.utils.SecurityUtils;

import com.ruoyi.common.core.web.page.TableDataInfo;

@Api(tags = "雨水")
@RestController
@RequestMapping("/rainwater")
public class SmdtvRainwaterController extends BaseController{
    
    @Autowired
    private ISmdtvRainwaterService smdtvRainwaterService;

    /**
     * 查询雨水列表
     */
    @GetMapping("/list")
    public TableDataInfo<?> list(SmdtvRainwater smdtvRainwater){
        startPage();
        List<SmdtvRainwater> list = smdtvRainwaterService.selectSmdtvRainwaterList(smdtvRainwater);
        return getDataTable(list);
    }

    /**
     * 根据id查询雨水
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        return AjaxResult.success(smdtvRainwaterService.selectSmdtvRainwaterById(id));
    }

    /**
     * 新增雨水
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmdtvRainwater smdtvRainwater){
        smdtvRainwater.setCreateTime(new Date());
        return toAjax(smdtvRainwaterService.save(smdtvRainwater));
    }

    /**
     * 修改雨水
     */
    @PutMapping
    public AjaxResult edit(@RequestBody SmdtvRainwater smdtvRainwater){
        return toAjax(smdtvRainwaterService.updateById(smdtvRainwater));
    }

    /**
     * 传入@PathVariable的格式类似为/1,2,3,4,5时,会自动转为数组
     */
    @Log(title = "雨水", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(smdtvRainwaterService.removeByIds(Arrays.asList(ids)));
    }
    
    /**
     * 导出雨水列表
     */
    @Log(title = "雨水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmdtvRainwater smdtvRainwater){
        List<SmdtvRainwater> list = smdtvRainwaterService.selectSmdtvRainwaterList(smdtvRainwater);
        ExcelUtil<SmdtvRainwater> util = new ExcelUtil<SmdtvRainwater>(SmdtvRainwater.class);
        util.exportExcel(response, list, "雨水数据");
    }
    
}
